The CommonMark spec (spec.txt) and DTD (CommonMark.dtd) are Copyright (C) 2014-16 John MacFarlane Released under the Creative Commons CC-BY-SA 4.0 license: . --- The test software in test/ and the programs in tools/ are Copyright (c) 2014, John MacFarlane All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- The normalization code in runtests.py was derived from the markdowntest project, Copyright 2013 Karl Dubost: The MIT License (MIT) Copyright (c) 2013 Karl Dubost Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 1372 Content-Disposition: inline; filename="cmark.py" Last-Modified: Mon, 15 Jul 2024 16:46:38 GMT Expires: Mon, 15 Jul 2024 16:51:38 GMT ETag: "1110860306d1126e6f948d6269c0b95358bef37e" #!/usr/bin/env python3 # -*- coding: utf-8 -*- from ctypes import CDLL, c_char_p, c_long from subprocess import * import platform import os def pipe_through_prog(prog, text): p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE) [result, err] = p1.communicate(input=text.encode('utf-8')) return [p1.returncode, result.decode('utf-8'), err] def use_library(lib, text): textbytes = text.encode('utf-8') textlen = len(textbytes) return [0, lib(textbytes, textlen, 0).decode('utf-8'), ''] class CMark: def __init__(self, prog=None, library_dir=None): self.prog = prog if prog: self.to_html = lambda x: pipe_through_prog(prog, x) else: sysname = platform.system() if sysname == 'Darwin': libname = "libcmark.dylib" elif sysname == 'Windows': libname = "cmark.dll" else: libname = "libcmark.so" if library_dir: libpath = os.path.join(library_dir, libname) else: libpath = os.path.join("build", "src", libname) cmark = CDLL(libpath) markdown = cmark.cmark_markdown_to_html markdown.restype = c_char_p markdown.argtypes = [c_char_p, c_long] self.to_html = lambda x: use_library(markdown, x) X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'none' Content-Type: text/plain; charset=UTF-8 Content-Length: 10519 Content-Disposition: inline; filename="coverage.txt" Last-Modified: Mon, 15 Jul 2024 16:46:38 GMT Expires: Mon, 15 Jul 2024 16:51:38 GMT ETag: "66d5cc8dc03c27d0dc91409d35de98bc92a5700d" # Coverage This file is just a collection of unit tests not covered elsewhere. Most notably regression tests, tests improving code coverage and other useful things may drop here. (However any tests requiring any additional command line option, like enabling an extension, must be included in their respective files.) ## GitHub Issues ### [Issue 2](https://github.com/mity/md4c/issues/2) Raw HTML block: ```````````````````````````````` example . ```````````````````````````````` Inline: ```````````````````````````````` example foo bar .

foo bar

```````````````````````````````` Inline with a line break: ```````````````````````````````` example foo bar .

foo bar

```````````````````````````````` ### [Issue 4](https://github.com/mity/md4c/issues/4) ```````````````````````````````` example ![alt text with *entity* ©](img.png 'title') .

alt text with entity ©

```````````````````````````````` ### [Issue 9](https://github.com/mity/md4c/issues/9) ```````````````````````````````` example > [foo > bar]: /url > > [foo bar] .

foo bar

```````````````````````````````` ### [Issue 10](https://github.com/mity/md4c/issues/10) ```````````````````````````````` example [x]: x -
  • ```````````````````````````````` ### [Issue 11](https://github.com/mity/md4c/issues/11) ```````````````````````````````` example x [link](/url "foo – bar") x .

    x link x

    ```````````````````````````````` ### [Issue 14](https://github.com/mity/md4c/issues/14) ```````````````````````````````` example a***b* c* .

    a*b c

    ```````````````````````````````` ### [Issue 15](https://github.com/mity/md4c/issues/15) ```````````````````````````````` example ***b* c* .

    *b c

    ```````````````````````````````` ### [Issue 21](https://github.com/mity/md4c/issues/21) ```````````````````````````````` example a*b**c* .

    ab**c

    ```````````````````````````````` ### [Issue 33](https://github.com/mity/md4c/issues/33) ```````````````````````````````` example ```&&&&&&&& .
    ```````````````````````````````` ### [Issue 36](https://github.com/mity/md4c/issues/36) ```````````````````````````````` example __x_ _x___ .

    x x_

    ```````````````````````````````` ### [Issue 39](https://github.com/mity/md4c/issues/39) ```````````````````````````````` example [\\]: x . ```````````````````````````````` ### [Issue 40](https://github.com/mity/md4c/issues/40) ```````````````````````````````` example [x](url 'title' )x .

    xx

    ```````````````````````````````` ### [Issue 65](https://github.com/mity/md4c/issues/65) ```````````````````````````````` example ` .

    `

    ```````````````````````````````` ### [Issue 74](https://github.com/mity/md4c/issues/74) ```````````````````````````````` example [f]: - xx - .
    xx
    
    ```````````````````````````````` ### [Issue 78](https://github.com/mity/md4c/issues/78) ```````````````````````````````` example [SS ẞ]: /url [ẞ SS] .

    ẞ SS

    ```````````````````````````````` ### [Issue 83](https://github.com/mity/md4c/issues/83) ```````````````````````````````` example foo > .

    foo

    ```````````````````````````````` ### [Issue 95](https://github.com/mity/md4c/issues/95) ```````````````````````````````` example . foo .

    . foo

    ```````````````````````````````` ### [Issue 96](https://github.com/mity/md4c/issues/96) ```````````````````````````````` example [ab]: /foo [a] [ab] [abc] .

    [a] ab [abc]

    ```````````````````````````````` ```````````````````````````````` example [a b]: /foo [a b] .

    a b

    ```````````````````````````````` ### [Issue 97](https://github.com/mity/md4c/issues/97) ```````````````````````````````` example *a **b c* d** .

    a b c d

    ```````````````````````````````` ### [Issue 100](https://github.com/mity/md4c/issues/100) ```````````````````````````````` example .

    foo@123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890123

    ```````````````````````````````` ```````````````````````````````` example .

    <foo@123456789012345678901234567890123456789012345678901234567890123x.123456789012345678901234567890123456789012345678901234567890123>

    ```````````````````````````````` (Note the `x` here which turns it over the max. allowed length limit.) ### [Issue 107](https://github.com/mity/md4c/issues/107) ```````````````````````````````` example ***foo *bar baz*** .

    *foo bar baz

    ```````````````````````````````` ### [Issue 124](https://github.com/mity/md4c/issues/124) ```````````````````````````````` example ~~~ x ~~~ ~~~ x ~~~ .
                    x
    
                     x
    
    ```````````````````````````````` ### [Issue 131](https://github.com/mity/md4c/issues/131) ```````````````````````````````` example [![alt][img]][link] [img]: img_url [link]: link_url .

    alt

    ```````````````````````````````` ### [Issue 142](https://github.com/mity/md4c/issues/142) ```````````````````````````````` example [fooﬗ]: /url [fooﬕ] .

    [fooﬕ]

    ```````````````````````````````` ### [Issue 149](https://github.com/mity/md4c/issues/149) ```````````````````````````````` example - .
    ```````````````````````````````` ## Code coverage ### `md_is_unicode_whitespace__()` Unicode whitespace (here U+2000) forms a word boundary so these cannot be resolved as emphasis span because there is no closer mark. ```````````````````````````````` example *foo *bar .

    *foo *bar

    ```````````````````````````````` ### `md_is_unicode_punct__()` Ditto for Unicode punctuation (here U+00A1). ```````````````````````````````` example *foo¡*bar .

    *foo¡*bar

    ```````````````````````````````` ### `md_get_unicode_fold_info()` ```````````````````````````````` example [Příliš žluťoučký kůň úpěl ďábelské ódy.] [PŘÍLIŠ ŽLUŤOUČKÝ KŮŇ ÚPĚL ĎÁBELSKÉ ÓDY.]: /url .

    Příliš žluťoučký kůň úpěl ďábelské ódy.

    ```````````````````````````````` ### `md_decode_utf8__()` and `md_decode_utf8_before__()` ```````````````````````````````` example á*Á (U+00E1, i.e. two byte UTF-8 sequence)  *  (U+2000, i.e. three byte UTF-8 sequence) .

    á*Á (U+00E1, i.e. two byte UTF-8 sequence) * (U+2000, i.e. three byte UTF-8 sequence)

    ```````````````````````````````` ### `md_is_link_destination_A()` ```````````````````````````````` example [link]() .

    link

    ```````````````````````````````` ### `md_link_label_eq()` ```````````````````````````````` example [foo bar] [foo bar]: /url .

    foo bar

    ```````````````````````````````` ### `md_is_inline_link_spec()` ```````````````````````````````` example > [link](/url 'foo > bar') .

    link

    ```````````````````````````````` ### `md_build_ref_def_hashtable()` All link labels in the following example all have the same FNV1a hash (after normalization of the label, which means after converting to a vector of Unicode codepoints and lowercase folding). So the example triggers quite complex code paths which are not otherwise easily tested. ```````````````````````````````` example [foo]: /foo [qnptgbh]: /qnptgbh [abgbrwcv]: /abgbrwcv [abgbrwcv]: /abgbrwcv2 [abgbrwcv]: /abgbrwcv3 [abgbrwcv]: /abgbrwcv4 [alqadfgn]: /alqadfgn [foo] [qnptgbh] [abgbrwcv] [alqadfgn] [axgydtdu] .

    foo qnptgbh abgbrwcv alqadfgn [axgydtdu]

    ```````````````````````````````` For the sake of completeness, the following C program was used to find the hash collisions by brute force: ~~~ #include #include static unsigned etalon; #define MD_FNV1A_BASE 2166136261 #define MD_FNV1A_PRIME 16777619 static inline unsigned fnv1a(unsigned base, const void* data, size_t n) { const unsigned char* buf = (const unsigned char*) data; unsigned hash = base; size_t i; for(i = 0; i < n; i++) { hash ^= buf[i]; hash *= MD_FNV1A_PRIME; } return hash; } static unsigned unicode_hash(const char* data, size_t n) { unsigned value; unsigned hash = MD_FNV1A_BASE; int i; for(i = 0; i < n; i++) { value = data[i]; hash = fnv1a(hash, &value, sizeof(unsigned)); } return hash; } static void recurse(char* buffer, size_t off, size_t len) { int ch; if(off < len - 1) { for(ch = 'a'; ch <= 'z'; ch++) { buffer[off] = ch; recurse(buffer, off+1, len); } } else { for(ch = 'a'; ch <= 'z'; ch++) { buffer[off] = ch; if(unicode_hash(buffer, len) == etalon) { printf("Dup: %.*s\n", (int)len, buffer); } } } } int main(int argc, char** argv) { char buffer[32]; int len; if(argc < 2) etalon = unicode_hash("foo", 3); else etalon = unicode_hash(argv[1], strlen(argv[1])); for(len = 1; len <= sizeof(buffer); len++) recurse(buffer, 0, len); return 0; } ~~~ Content-Type: text/plain; charset=UTF-8 Content-Length: 10519 Content-Disposition: inline; filename="coverage.txt" Last-Modified: Mon, 15 Jul 2024 16:46:38 GMT Expires: Mon, 15 Jul 2024 16:51:38 GMT ETag: "fd1b46994725e0fd70d57d65070d18afa8bad00a" /tdemarkdown/md4c/test/fuzz-input/

    /tdemarkdown/md4c/test/fuzz-input/